-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
pr05 Typescript #8: migrate client/components/Menubar/MenubarSubmenu #3623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
pr05 Typescript #8: migrate client/components/Menubar/MenubarSubmenu #3623
Conversation
MENU = MenubarListItemRole.MENU, | ||
LISTBOX = MenubarListItemRole.LISTBOX, | ||
TRUE = 'true' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khanniie I'm not 100% if this was the correct approach
I was a bit confused because the original file had the below:
MenubarTrigger.propTypes = {
role: PropTypes.string,
hasPopup: PropTypes.oneOf(['menu', 'listbox', 'true'])
};
MenubarList.propTypes = {
children: PropTypes.node,
role: PropTypes.oneOf(['menu', 'listbox'])
};
I made the assumption the menu bar list item roles and menubar trigger aria-hasPopup are associated in the relationship defined in the enums??
Should we just remove TRUE? I didn't see TRUE being used elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on the web docs (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-haspopup#description), it looks like they're supposed to be the same!
"Make sure the role of the element that serves as the container for the popup content is a menu, listbox, tree, grid or dialog and that the value of aria-haspopup matches the role of the popup container."
in other words, my understanding is that aria-haspopup
is telling the assistive device what kind of container the "trigger button" is about to open, so it should match the type of our submenu containers.
so it should be either menu or listbox, like you said -- i guess true is a valid value (docs say "The value true is the same as menu") but if we're never using it, we should remove
const { isOpen, handlers } = useMenuProps(id); | ||
|
||
// `ref` is always a button from MenubarSubmenu, so safe to cast. | ||
const buttonRef = ref as React.RefObject<HTMLButtonElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wasn't sure how to resolve this other than casting, but I thought was safe bc this function is only used within this file once and it's always a button ref
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm!! it's kind of surprising to me that typescript wouldn't be able to infer that from the React.forwardRef function params since you gave it the HTMLButtonElement type there but i trust that it doesn't work without casting haha
title, | ||
triggerRole: customTriggerRole, | ||
listRole: customListRole, | ||
triggerRole = 'menuitem', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if string is too loose here, or if there is a specific enum we should be using?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer to you but we could add another enum for list item roles! since you already have one for the list itself. i think the type would be either menuitem (for the 'menu' containers) or option (for the 'listbox' containers)
…ild__MenubarSubmenu_attempt_2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks so much for putting this together! it was definitely a very complicated file haha but great work
MENU = MenubarListItemRole.MENU, | ||
LISTBOX = MenubarListItemRole.LISTBOX, | ||
TRUE = 'true' | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
based on the web docs (https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-haspopup#description), it looks like they're supposed to be the same!
"Make sure the role of the element that serves as the container for the popup content is a menu, listbox, tree, grid or dialog and that the value of aria-haspopup matches the role of the popup container."
in other words, my understanding is that aria-haspopup
is telling the assistive device what kind of container the "trigger button" is about to open, so it should match the type of our submenu containers.
so it should be either menu or listbox, like you said -- i guess true is a valid value (docs say "The value true is the same as menu") but if we're never using it, we should remove
const { isOpen, handlers } = useMenuProps(id); | ||
|
||
// `ref` is always a button from MenubarSubmenu, so safe to cast. | ||
const buttonRef = ref as React.RefObject<HTMLButtonElement>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sgtm!! it's kind of surprising to me that typescript wouldn't be able to infer that from the React.forwardRef function params since you gave it the HTMLButtonElement type there but i trust that it doesn't work without casting haha
|
||
export function useMenuProps(id) { | ||
/** Custom subset of valid list item roles for the Menubar list items */ | ||
export enum MenubarListItemRole { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit but it looks like these are values for the container, not the items within the container? should we update the comment and interface name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe like "MenuContainerRole"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also agree, I think it might make sense to update the name here!
title, | ||
triggerRole: customTriggerRole, | ||
listRole: customListRole, | ||
triggerRole = 'menuitem', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
defer to you but we could add another enum for list item roles! since you already have one for the list itself. i think the type would be either menuitem (for the 'menu' containers) or option (for the 'listbox' containers)
Thanks so much for your work on this! I also think this looks great, and I really like how the refactor for the menubarsubmenu component feels more straightforward and easy to read! Can hold on merging if you'd like to make any further tweaks! |
…ild__MenubarSubmenu_attempt_2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one small comment but overall LGTM! thank you so much!
* -----------------------------------------------------------------------------------------------*/ | ||
|
||
/** Custom subset of valid values for aria-hasPopup for the MenubarTrigger */ | ||
enum MenubarTriggerAriaHasPopup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a bit of a nit but if it looks exactly the same as menucontainerrole why not just use that instead of duplicating?
pr05 Typescript Migration 8: Migrate the client/components/Menubar/MenubarSubmenu
Context:
Changes:
Other:
Notes:
I have verified that this pull request:
npm run lint
)npm run test
)develop
branch.Fixes #123